package com.xjh.basestudy.designmode.behaviorMode.behaviorMode6_Memento.p1_origin;

/**
 * @Author XuJianHua
 * @Date 2022/10/4 20:11
 * @Description

 */
public class Editor {

    private Doc doc;//文档引用

    public Editor(Doc doc) {
        System.out.println("<<<打开文档" + doc.getTitle());
        this.doc = doc;//载入文档
        show();
    }

    public void append(String txt) {
        System.out.println("<<<插入操作");
        doc.setBody(doc.getBody() + txt);
        show();
    }

    public void delete(){
        System.out.println("<<<删除操作");
        doc.setBody("");
        show();
    }

    public void save(){
        System.out.println("<<<存盘操作");
    }

    private void show(){//显示当前文档内容
        System.out.println(doc.getBody());
        System.out.println("文档结束>>>\n");
    }

}